﻿using BrnMall.Manager.Domain.Messages;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.Messages
{
    public static class CreateDesignManager
    {
        /// <summary>
        /// 新增创意信息
        /// </summary>
        /// <param name="DesignModel"></param>
        /// <returns></returns>
        public static bool AddDesign(CreateDesigns DesignModel)
        {
            object obj = null;
            using (var db = new QDMallDatabase())
            {
                obj = db.Insert(DesignModel);
            }
            if (obj != null)
                return true;
            return false;
        }

        /// <summary>
        /// 修改留言信息
        /// </summary>
        /// <param name="DesignModel"></param>
        /// <returns></returns>
        public static bool UpdateDesign(CreateDesigns DesignModel)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Update(DesignModel);
            }
            return count > 0 ? true : false;
        }


        public static bool Edit(int storeId, string DesignName)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute(string.Format("update bma_CreateDesign set DesignName='{0}' where storeId={1}", DesignName, storeId));
            }
            return count > 0 ? true : false;
        }

        /// <summary>
        /// 删除留言
        /// </summary>
        /// <param name="Designid"></param>
        /// <returns></returns>
        public static bool DeleteDesign(int Designid)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute("delete bma_CreateDesign where DesignID=@0", Designid);
            }
            return count > 0 ? true : false;
        }

        public static CreateDesigns GetDesign(int storeId)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<CreateDesigns>(string.Format("select top 1 * from  bma_CreateDesign where storeId={0}", storeId));
            }
        }

        /// <summary>
        /// 留言列表，按ID排序
        /// </summary>
        /// <param name="storeId"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<CreateDesigns> GetListByAmount(int pageSize = 50)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<CreateDesigns>(string.Format("select top {0} * from bma_CreateDesign order by DesignID desc", pageSize));
            }
        }
        /// <summary>
        /// 获取选项列
        /// </summary>
        /// <param name="Designid"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<CreateDesigns> GetList(int Designid, int pageSize = 10)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Fetch<CreateDesigns>(string.Format("select top {0} * from bma_CreateDesign where DesignID={1}  order by DesignID desc", pageSize, Designid));
            }
        }
    }
}
